package sdwan_data

import (
	"fmt"
	"github.com/sirupsen/logrus"
	"smart-sensor-cloud/internal/model"
)

func GetSystemOptions() {

	hosts, err := model.GetAllHost()

	if err != nil {
		return
	}

	for _, host := range hosts {
		fmt.Println(host.IP, host.Port, host.Username, host.Password)
		SystemOption, err := client.GetSystemOption(host.IP, host.Port)
		if err != nil {
			logrus.Error(err)
		} else {
			host.SerialNo = SystemOption.SystemOption.SerialNo
			host.Name = SystemOption.SystemOption.SiteName
			host.ApplianceMode = SystemOption.SystemOption.ApplicationMode
			host.ApplianceUptime = SystemOption.SystemOption.ApplianceUptime
			host.ServiceUptime = SystemOption.SystemOption.ServiceUptime
			host.SystemTime = SystemOption.SystemOption.SystemTime
			model.UpdateHost(int(host.ID), host)
			logrus.Info("调用Nitro Login API，采集SystemOptions信息成功")
		}
	}

}

func GetEthernetStats() {
	hosts, err := model.GetAllHost()

	if err != nil {
		return
	}

	for _, host := range hosts {
		err := client.GetEthernetStats(host.IP, host.Port)
		if err != nil {
			logrus.Error(err)
		} else {
			logrus.Info("调用Nitro Login API，采集ethernet_stats信息成功")
		}
	}
}

func GetWanLinkUsageStats() {
	hosts, err := model.GetAllHost()

	if err != nil {
		return
	}

	for _, host := range hosts {
		err := client.GetWanLinkUsageStats(host.IP, host.Port)
		if err != nil {
			logrus.Error(err)
		} else {
			logrus.Info("调用Nitro Login API，wan_link_usage_stats")
		}
	}
}
